package Euler54;

public class Card implements Comparable<Card> {
	public enum RANK
	{
	    TWO,
	    THREE,
	    FOUR,
	    FIVE,
	    SIX,
	    SEVEN,
	    EIGHT,
	    NINE,
	    TEN,
	    JACK,
	    QUEEN,
	    KING,
	    ACE
	}
	
	public enum SUIT
	{
		CLUBS,
		DIAMONDS,
		HEARTS,
		SPADES
	}
	
	private RANK rank;
	private SUIT suite;
	
	public Card(RANK rank, SUIT suite)
	{
		this.rank = rank;
		this.suite = suite;
	}
	
	public Card(String token)
	{	
		String rk = token.substring(0,1);
		String st = token.substring(1,2);
		
		this.rank = strToRank(rk);
		this.suite = strToSuit(st);
	}
	
	public RANK getRank()
	{
		return rank;
	}
	
	public SUIT getSuite()
	{
		return suite;
	}
	
	private RANK strToRank(String rk)
	{
		switch (rk) 
		{
	        case "2": return RANK.TWO;
	        case "3": return RANK.THREE;
	        case "4": return RANK.FOUR;
	        case "5": return RANK.FIVE;
	        case "6": return RANK.SIX;
	        case "7": return RANK.SEVEN;
	        case "8": return RANK.EIGHT;
	        case "9": return RANK.NINE;
	        case "T": return RANK.TEN;
	        case "J": return RANK.JACK;
	        case "Q": return RANK.QUEEN;
	        case "K": return RANK.KING;
	        case "A": return RANK.ACE;
	        default: return RANK.TWO;
		}
	}
	
	private SUIT strToSuit(String st)
	{
		switch (st) 
		{
	        case "S": return SUIT.SPADES;
	        case "H": return SUIT.HEARTS;
	        case "C": return SUIT.CLUBS;
	        case "D": return SUIT.DIAMONDS;
	        default: return SUIT.SPADES;
		}
	}
	
	@Override
    public int compareTo(Card other)
	{
        return this.rank.compareTo(other.getRank());
    }
	
	@Override
    public String toString()
	{
        return rank.toString() + " of " + suite.toString();
    }
}
